<template>
	<div class="task-preview-container">
		<div class="task-details">
			<div class="task-info">
				<span class="info-label">编程语言:</span>
				<span class="info-value">{{ taskData.langName }}</span>
			</div>
			<div class="task-info">
				<span class="info-label">模块名称:</span>
				<span class="info-value">{{ taskData.module }}</span>
			</div>
			<div class="task-info">
				<span class="info-label">难易程度:</span>
				<span class="info-value">{{ taskData.leave }}</span>
			</div>
		</div>
		<div class="task-content">{{ taskData.title }}
<pre><code></code></pre>
		</div>

    <!-- 任务答案和列表 -->
    <div class="flex gap-2 task-code-list">
      <el-check-tag
          v-for="student in taskData.results"
          :key="student.student_id"
          :checked="selectedStudentId === student.student_id"
          @click="handleStudentFilter(student.student_id)"
      >
        {{ student.student_name }}
      </el-check-tag>

    </div>
    <!-- 显示任务答案 -->
    <pre class="task-answer" v-if="currentStudentAnswer">
      <code>{{currentStudentAnswer}}</code>
		</pre>
  </div>


</template>

<script>

import HeaderNav from '@/components/HeaderNav.vue'
import TaskContainer from '@/components/TaskContainer.vue'
import TaskCode from '@/components/TaskCode.vue'

export default {
  props: {
    // 存储需要的信息
    taskData: {
      type: Object,
      required: true
    }
  },
  components: {
    HeaderNav,
    TaskContainer,
    TaskCode,
  },
  data() {
    return {
      active: 0,
      task: {
        checked: false,
        code: "",
      },
      selectedStudentId: this.taskData.results.length > 0 ? this.taskData.results[0].student_id : null
    }
  },
  computed: {
    // 找到当前选中学生对应的答案
    currentStudentAnswer() {
      if (!this.selectedStudentId) return null;
      const student = this.taskData.results.find(
          s => s.student_id === this.selectedStudentId
      );
      return student ? student.answer : null;
    }
  },
  methods: {
    handleStudentFilter(studentId) {
      this.selectedStudentId = studentId;
    }
  },
}
</script>

<style scoped>
.task-preview-container {
  margin: 0 auto;
  padding: 20px;
  background-color: #f9f9f9;
  border-radius: 10px;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
  height: 700px;
  overflow: auto;
  position: relative;
}

.task-header {
  text-align: center;
  margin-bottom: 20px;
}

.task-title {
  font-size: 28px;
  font-weight: bold;
  color: #333;
}

.task-details {
  display: flex;
  justify-content: space-between;
  line-height: 40px;
  background-color: #fff;
  margin-bottom: 10px;
  border-radius: 8px;
}

.task-info {
  flex: 1;
  text-align: center;
}

.info-label {
  font-weight: bold;
  color: #555;
  margin-right: 10px;
}

.info-value {
  color: #777;
}

.task-content {
  background: #fff;
  padding: 15px;
  border-radius: 8px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.task-content pre:has(>code) {
  background: #F0F2F5;
  color: #333;
  padding: 10px;
  border-radius: 5px;
  overflow-x: auto;
}

.task-content code {
  font-family: 'Courier New', Courier, monospace;
  font-size: 14px;
}

.el-carousel__item h3 {
  color: #475669;
  opacity: 0.75;
  line-height: 200px;
  margin: 0;
  text-align: center;
}

.task-code-list {
  padding: 20px 0;
}

.task-answer {
  background-color: #fff;
  padding: 10px 20px;
  border-radius: 5px;
  overflow: auto;
  line-height: 1.5;
  margin: 10px 0;
  tab-size: 3;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  /* 限制宽高，触发滚动条 */
  max-height: 400px;  /* 根据需要调整 */
  max-width: 100%;    /* 或固定宽度，比如 600px */
  white-space: pre;   /* 保持换行格式，不自动换行 */
}

.task-answer > code {
  font-family: 'Courier New', Courier, monospace;
  font-size: 14px;
  line-height: 1.1;
}

.el-check-tag {
  margin: 0 3px;
  background-color: #e9e9eb;
}

.el-check-tag[disabled] {
  background-color: #f4f4f5;
}

.el-check-tag[disabled]:hover {
  cursor: not-allowed;
}
</style>